package org.cid54.jshopper.util;

import java.util.Random;
import java.util.UUID;
import org.springframework.stereotype.Component;

/**
 *
 * @author fgo
 */
@Component
public class Hashher {

    private static Random rg = new Random();

    public String getNewGuid() {

        UUID uuid = UUID.randomUUID();
        return uuid.toString().replace("-", "");

    }

    public String getRandomSalt() {

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < 32; i++) {
            sb.append((char) ('a' + rg.nextInt(27)));
        }

        return sb.toString();
    }

    public String getHash(String password, String salt) {

        int passwdhash = password.hashCode();

        int salthash = salt.hashCode();

        int result = passwdhash | salthash;

        return "" + result;
    }
}
